class LoadingUI extends egret.Sprite {

    static _self = null;
    static createObj(){
        if(!LoadingUI._self){
            LoadingUI._self = new LoadingUI();
        }
        return LoadingUI._self;
    }


    /****************************** 资源与loading配置 ***************************/

    // static resUrl: string   = "resource/default.res.json";
    // static resRoot: string  = "resource/";
    // static resGroup: string = "loading";


    public constructor() {
        super();
        this.addEventListener(egret.Event.ADDED_TO_STAGE, this.createView, this);
    }

    private textField: egret.TextField;

    private createView():void {
        this.removeEventListener(egret.Event.ADDED_TO_STAGE, this.createView, this);
        // let loadImg = new egret.Bitmap();
        // let texture: egret.Texture = RES.getRes('loading_jpg');
        // loadImg.texture = texture;
        // this.addChild(loadImg);

        this.graphics.beginFill(0xffffff);
        this.graphics.drawRect(0, 0, this.stage.stageWidth, this.stage.stageHeight);
        this.graphics.endFill();

        this.textField = new egret.TextField();
        this.addChild(this.textField);
        this.textField.width = this.stage.stageWidth;
        this.textField.height = this.stage.stageHeight;
        this.textField.textAlign = egret.HorizontalAlign.CENTER;
        this.textField.verticalAlign = egret.VerticalAlign.MIDDLE;
        this.textField.textColor = 0x000000;
    }

    public setProgress(current:number, total:number):void {
        this.textField.text = `Loading...${current}/${total}`;
    }
}
